<template>
  <div>
    <el-calendar v-if="show" v-model="currentDay" :first-day-of-week="1">
      <template #dateCell="{ date, data }">
        <div class="date-content">
          <span class="text"> {{ formateDate(data) }}</span>
          <span v-if="isWeekend(date)" class="rest">休</span>
        </div>
      </template>
    </el-calendar>
  </div>
</template>

<script>
export default {
  data () {
    return {
      show: true,
      currentDay: new Date()
    }
  },
  watch: {
    async '$i18n.locale' (newValue) {
      this.show = false
      await this.$nextTick()
      this.show = true
    }
  },
  methods: {
    formateDate (data) {
      return data.day.split('-')[2]
    },
    isWeekend (time) {
      return time.getDay() === 6 || time.getDay() === 0
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-calendar-day {
  height: 50px;
}
// 日历内容自定义样式
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
// 休息时间
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
// 当前日期
::v-deep .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}
</style>

